package com.yh.blog.serviceImpl;

import com.yh.blog.config.PersonConfig;
import com.yh.blog.domain.Picture;
import com.yh.blog.mapper.PictureMapper;
import com.yh.blog.service.PictureService;
import com.yh.blog.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class PictureServiceImpl implements PictureService {
    @Resource
    private PictureMapper pictureMapper;
    @Autowired
    private PersonConfig personConfig;
    @Override
    public boolean append(Picture picture) {
        return this.pictureMapper.insert(picture);
    }

    @Override
    public boolean remove(Integer pictureId) {
        return this.pictureMapper.delete(pictureId);
    }

    @Override
    public boolean modify(Picture picture) {
        return this.pictureMapper.update(picture);
    }

    @Override
    public Picture detail(Integer pictureId) {
        return this.pictureMapper.selectById(pictureId);
    }

    @Override
    public Pager<Picture> list(Integer page) {
        List<Picture> datas=this.pictureMapper.selects((page-1)*this.personConfig.getPage_size(),this.personConfig.getPage_size());
        int size=this.pictureMapper.size();
        return new Pager<>(datas, size, page, this.personConfig.getPage_size());
    }

    @Override
    public List<Picture> list() {
        return this.pictureMapper.selects(0, 0);
    }
}
